package com.effectivcrm;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.mongodb.config.AbstractMongoConfiguration;
import org.springframework.data.mongodb.core.SimpleMongoDbFactory;
import org.springframework.data.mongodb.repository.config.EnableMongoRepositories;

import com.mongodb.Mongo;

import com.mongodb.WriteConcern;

@Configuration
@EnableMongoRepositories(basePackages = "com.effectivcrm.repository")
public class MongoConfiguration  extends AbstractMongoConfiguration{

	@Override
	protected String getDatabaseName() {
		return "crm";
	}

	//TODO - change and remove the deprecated method
	@Override
	public Mongo mongo() throws Exception {
		
		Mongo m = new Mongo();
		
		m.setWriteConcern(WriteConcern.SAFE);
		return m;
	}

	@Override
	@Bean
	public SimpleMongoDbFactory mongoDbFactory() throws Exception {
		// return new SimpleMongoDbFactory(mongo(), getDatabaseName(), new
		// UserCredentials("admin", "admin1612"));
		return new SimpleMongoDbFactory(mongo(), getDatabaseName());
	}

	@Override
	protected String getMappingBasePackage() {

		return "com.effectivcrm.domain";
	}

}
